define(
		[ "PDUtilDir/grid", "PDUtilDir/util", "PDUtilDir/tool", "PDUtilDir/slidebar",
				"PDUtilDir/inputSelect",
				"PDUtilDir/fileupload/singleFileUpload", "Date", "DateCN",
				"css!DateCss", "PicView", "css!picViewCss",
				"css!AppPathDir/order/orderInfos/views/css/css" ],
		function(Grid, Util, Tool, Slidebar, inputSelect, MFU) {
			function detailSupportInit($scope, $compile) {
				return new detailSupport($scope, $compile);
			}
			function detailSupport($scope, $compile) {
				this.$scope = $scope;
				this.$compile = $compile;
			}
			detailSupport.fn = detailSupport.prototype;
			detailSupport.fn.digest = function() {
				this.$scope.$digest();
			};
			detailSupport.fn.init = function(id) {
                var _this = this;
                _this.cache = {
                    certificatesMap: new Map(),
                    typeMap: new Map(),
                }
                _this.entity = {
                    visitors: new Array()
                }
                // 证件类型
                $.ajax({
                    url : getServer() + "/flea/hclv/getCertificates.htmls",
                    success : function(data) {
                        $.each(data.data, function(index, row) {
                            _this.cache.certificatesMap.set(row.dictCode, row.dictName);
                        });
                        _this.initVisitor();
                    }
                });
                //游客类型
                $.ajax({
                    url : getServer() + "/flea/hclv/getVisitorType.htmls",
                    success : function(data) {
                        $.each(data.data, function(index, row) {
                            _this.cache.typeMap.set(row.dictCode, row.dictName);
                        });
                        _this.initVisitor();
                    }
                });
			    $.ajax({
					url : getServer() + "/flea/hclv/serviceOrder/findDetailById.htmls",
					data: {
				    	model : id,
				    },
					success : function(data) {
						_this.entity = data.data.order;
                        _this.entity.visitors = data.data.visitors;
						_this.entity.orderStatusName = _this.$scope.cache.orderStatusMap.get(_this.entity.payStatus);
                        _this.initVisitor();
						_this.digest();
					}
				});
			};
			detailSupport.fn.run = function(data) {
				var _this = this;
				_this.init(data);
				this.slidebars = Slidebar({
					size : 'lg',
					url : getServer() + "/static/app/order/buyOrderInfos/views/detail.html",
//					close : true,
					$scope : this.$scope,
					$compile : this.$compile,
					afterLoad : function($Panel) {
						_this.initialization();
					}
				});
			};
			detailSupport.fn.initialization = function() { };
            detailSupport.fn.initVisitor = function() {
                var _this = this;
                if(_this.cache.typeMap.size > 0 && _this.cache.certificatesMap.size > 0 && _this.entity.visitors.length > 0){
                    Grid({
                        id : "GirdVisitorDivId",
                        // pageSize : 10,
                        index : true,
                        // multi : true,
                        pagination : false,
                        cache : false,
                        layout : [
                            {
                                name : "中文名",
                                field : "zhName"
                            },
                            {
                                name : "英文名",
                                field : "enName"
                            },
                            {
                                name : "类型",
                                field : "type",
                                format : function(e) {
                                    return _this.cache.typeMap.get(e.row.type);
                                }
                            },
                            {
                                name : "性别",
                                field : "sex",
                                format : function(e) {
                                    if (e.row.sex == "1")
                                        return '男';
                                    else
                                        return '女';
                                }
                            },
                            {
                                name : "年龄",
                                field : "age"
                            },
                            {
                                name : "联系电话",
                                field : "phone"
                            },
                            {
                                name : "证件类型",
                                field : "certificates",
                                format : function(e) {
                                    return _this.cache.certificatesMap.get(e.row.certificates);
                                }
                            }, {
                                name : "证件号码",
                                field : "certificatesNumber"
                            } ],
                        toolbar : [ ],
                        data : this.entity.visitors
                    });
                }
            };
			return detailSupportInit;
		});